package com.xxx.auth.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@Entity
@Comment("权限分组目录")
@Table(name = "t_permission_category")
@EntityListeners(AuditingEntityListener.class)
public class PermissionCategory extends TimeEntity implements Serializable {

    public static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(generator = "CustomUUID")
    @GenericGenerator(name = "CustomUUID", strategy = "com.xxx.auth.common.generator.CustomUUIDGenerator")
    @Column(name = "id", unique = true)
    private String id;

    @Column
    @Comment("名称")
    @Schema(title = "名称")
    private String name;

    @Column
    @Comment("描述")
    @Schema(title = "描述")
    private String description;

    @OneToMany(mappedBy = "permissionCategory")
    @JsonIgnore
    private Set<Permission> permissionSet = new HashSet<>();

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PermissionCategory that = (PermissionCategory) o;
        return Objects.equals(name, that.name) &&
                Objects.equals(description, that.description);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, description);
    }

}
